package com.dt76.smallloanbackenduser.controller.ysy;

import com.dt76.smallloanbackenduser.remote.ysy.ManageRemote;
import com.dt76.smallloanbackenduser.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("ysy")
public class ManageController {
    @Autowired
    private ManageRemote manageRemote;

    /*
       动态查询 + 带分页
    */
    @RequestMapping("/manage")
    public String qryConditionPageAll(Model model, Integer currentPageNo,
                                      @RequestParam(value = "queryname",required = false)String queryname,
                                      @RequestParam(value = "queryUserRole",required = false)String roleId) {
        if (currentPageNo <= 0) {
            currentPageNo = 1;
        }
        //02.调用动态查询+分页查询接口
        String paramName = "";
        if(queryname != null && !queryname.equals("")){
            paramName = "%"+queryname+"%";
        }
        if(roleId == null){roleId = "0";}
//        System.out.println("paramName:"+paramName);
        Page page = manageRemote.qryPageConditionAll(currentPageNo, paramName, roleId);

        //03.组织返回值
        model.addAttribute("queryUserList", page.getRows());//用户列表
        //加入角色列表，调用角色查询的接口
        model.addAttribute("page", page);
        //加入动态查询条件返回
        model.addAttribute("queryname",queryname);
        model.addAttribute("queryUserRole",roleId);
        return "pages/ysy/manage";
    }
}
